package cc.admin.modules.sys.service.impl;

import cc.admin.common.sys.vo.LoginUser;
import cc.admin.modules.sys.entity.SysPosition;
import cc.admin.modules.sys.mapper.SysPositionMapper;
import cc.admin.modules.sys.mapper.SysUserMapper;
import cc.admin.modules.sys.service.ISysPositionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description: 岗位管理
 * @Author: cc-admin
 * @Date:   2022-01-13
 * @Version: V1.0.0
 */
@Service
public class SysPositionServiceImpl extends ServiceImpl<SysPositionMapper, SysPosition> implements ISysPositionService {

    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public void updateUserPostName(SysPosition sysPosition) {
        sysUserMapper.updateUserPostName(sysPosition.getId(),sysPosition.getPostName());

    }

    @Override
    public List<Map<String, Object>> postList(String type) {
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<Map<String, Object>> list =new ArrayList<>();
        String sql=String.format("select post_code,post_name from sys_position where type=? and LENGTH(post_code)>0 and tenant_id=? order by px ");
        list=jdbcTemplate.queryForList(sql,type,user.getTenantId());
        return list;
    }
}
